IF OBJECT_ID('ssf.job_add_job_category') IS NOT NULL
	DROP PROCEDURE ssf.job_add_job_category
GO

CREATE PROCEDURE ssf.job_add_job_category
	@category NVARCHAR(128)
AS
/*
<object_header>

<object_summary>
	<purpose><![CDATA[
Add a job category if it does not exist.
	]]></purpose>
</object_summary>

</object_header>
*/

SET NOCOUNT ON

-- ============
/*<code_comment><![CDATA[declare local variables]]></code_comment>*/
DECLARE	@category_class INT = 1 -- Job
			, @proc_error INT
-- ============

-- ============
/*<code_comment><![CDATA[add category if it does not exist]]></code_comment>*/
IF NOT EXISTS (
	SELECT *
	FROM msdb.dbo.syscategories
	WHERE [name] = @category
	AND category_class = @category_class
)
BEGIN
	EXECUTE @proc_error = msdb.dbo.sp_add_category
		@name = @category

	IF @proc_error <> 0
	BEGIN
		RAISERROR('The call to the procedure <msdb.dbo.sp_add_category> failed.', 16, 1)
		RETURN @proc_error
	END
END
-- ============

RETURN @@ERROR
GO
